#ifndef FACTORY_H
#define FACTORY_H

#include "GameObject.h"
#include "Singleton.h"
#include <string>
#include <assert.h>

template <class T>
class Factory : public Uncopyable
{
	Factory(){}
	friend class Singleton<Factory>;
public:
	typedef T* (*Creator) ();
	typedef std::map<std::string, Creator> FactoryMap;

	T* Create(const std::string& typeName)
	{
		Creator c = m_map[typeName];
		if (c == nullptr)
		{
			std::wstring error = L"Bad game object name: " + std::wstring(typeName.begin(), typeName.end());
			DX11ErrorMsg(error.c_str(), L"Factory::Create()", MB_OK);
		}
		assert(c != 0);
		return c();
	}

	bool AddType(const std::string& typeName, Creator c)
	{
		m_map[typeName] = c;
		return true;
	}
private:
	FactoryMap m_map;
};

typedef Singleton<Factory<GameObject>> TheGameObjectFactory;

//typedef Singleton<Factory<TimelineKey>> TheTLKFactory;

#endif //FACTORY_H
